package algotithm.acwing.rangeofproblems.test803;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/28-23:28
 * @Title 803. 区间合并
 */
import java.io.*;
import java.util.*;
public class Main {


    private static ArrayList<int[]> list = new ArrayList<>();
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(String.valueOf(reader.readLine()));
        while (n-- >  0) {
            String[] num =  reader.readLine().split(" ");
            int[] arr = new int[2];
            arr[0] = Integer.parseInt(num[0]);
            arr[1] = Integer.parseInt(num[1]);
            list.add(arr);
        }

        list.sort(new Comparator<int[]>(){
            @Override
            public int compare(int[] o1,int[] o2) {
                return o1[0] - o2[0];
            }
        });

        int k = 0;
        int r = Integer.MIN_VALUE;
        for (int[] a : list) {
            if (a[0] > r) {
                k++;
            }
            r = Math.max(r,a[1]);
        }
        writer.write(k + "\n");
        writer.flush();
        writer.close();
        reader.close();
    }

}